﻿using System;
using System.Drawing;

namespace Simple3DRedactor.Domain
{
    public class Light : SceneObject
    {
        public Light()
        {
            Name = "Light";
            Ambient = Color.Black;
            Diffuse = Color.White;
            Specular = Color.White;
            ConstantAttenuation = 1.0f;
            LinearAttenuation = 0.0f;
            QuadraticAttenuation = 0.0f;
            SpotCutOff = 180.0f;
            SpotExponent = 0.0f;
        }

        private Color _ambient;
        public Color Ambient
        {
            get { return _ambient; }
            set
            {
                if (_ambient != value)
                {
                    _ambient = value;
                    OnChange();
                }
            }
        }

        private Color _diffuse;
        public Color Diffuse
        {
            get { return _diffuse; }
            set
            {
                if (_diffuse != value)
                {
                    _diffuse = value;
                    OnChange();
                }
            }
        }

        private Color _specular;
        public Color Specular
        {
            get { return _specular; }
            set
            {
                if (_specular != value)
                {
                    _specular = value;
                    OnChange();
                }
            }
        }

        private float _constantAttenuation;
        public float ConstantAttenuation
        {
            get { return _constantAttenuation; }
            set
            {
                if (Math.Abs(_constantAttenuation - value) > float.Epsilon)
                {
                    _constantAttenuation = value;
                    OnChange();
                }
            }
        }

        private float _linearAttenuation;
        public float LinearAttenuation
        {
            get { return _linearAttenuation; }
            set
            {
                if (Math.Abs(_linearAttenuation - value) > float.Epsilon)
                {
                    _linearAttenuation = value;
                    OnChange();
                }
            }
        }

        private float _quadraticAttenuation;
        public float QuadraticAttenuation
        {
            get { return _quadraticAttenuation; }
            set
            {
                if (Math.Abs(_quadraticAttenuation - value) > float.Epsilon)
                {
                    _quadraticAttenuation = value;
                    OnChange();
                }
            }
        }

        private float _cutOff;
        public float SpotCutOff
        {
            get { return _cutOff; }
            set
            {
                if (Math.Abs(_cutOff - value) > float.Epsilon)
                {
                    _cutOff = value;
                    OnChange();
                }
            }
        }

        private float _exponent;
        public float SpotExponent
        {
            get { return _exponent; }
            set
            {
                if (Math.Abs(_exponent - value) > float.Epsilon)
                {
                    _exponent = value;
                    OnChange();
                }
            }
        }

        public override TV CreateView<TV>(IObjectViewFactory<TV> factory)
        {
            return factory.Create(this);
        }
    }
}
